package com.yztc.yidoutang.adapter;

import android.content.Context;
import android.net.Uri;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.yztc.yidoutang.R;
import com.yztc.yidoutang.bean.DaRenListBean;
import com.yztc.yidoutang.utils.GlideCircleTransform;

import java.util.List;

/**
 * Created by My on 2016/10/19.
 */

public class DaRenAdapter extends BaseAdapter {
    private Context context;
    private List<DaRenListBean> list;
    private RequestManager manager;
    private ViewHolder holder;

    public DaRenAdapter(Context context, List<DaRenListBean> list) {
        this.context = context;
        this.list = list;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView= LayoutInflater.from(context).inflate(R.layout.item_drlv,null);
            holder=new ViewHolder();
            holder.iv= (ImageView) convertView.findViewById(R.id.dr_iv_lvitem);
            holder.iv_user= (ImageView) convertView.findViewById(R.id.dr_user);
            holder.tv_author= (TextView) convertView.findViewById(R.id.dr_tv_anthor);
            holder.tv_click= (TextView) convertView.findViewById(R.id.dr_tv_click);
            holder.tv_content= (TextView) convertView.findViewById(R.id.dr_tv_content);
            holder.tv_sign= (TextView) convertView.findViewById(R.id.dr_tv_lvitem_sign);
            holder.tv_look= (TextView) convertView.findViewById(R.id.dr_tv_look);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        manager= Glide.with(context);
        manager.load(Uri.parse(list.get(position).getFeature())).placeholder(R.mipmap.ic_default_load).into(holder.iv);
        manager.load(Uri.parse(list.get(position).getUserPic())).transform(new GlideCircleTransform(context)).into(holder.iv_user);
        holder.tv_look.setText(list.get(position).getViews()+"");
        holder.tv_sign.setText(list.get(position).getTagname());
        holder.tv_sign.setBackgroundResource(R.drawable.shape_jingxuan_daren);
        holder.tv_author.setText("by "+list.get(position).getAuthor()+"\n");
        holder.tv_content.setText(list.get(position).getSubject());
        holder.tv_click.setText(list.get(position).getSharings()+"");
        return convertView;
    }
    static class ViewHolder{
        ImageView iv;
        ImageView iv_user;
        TextView tv_sign;
        TextView tv_look;
        TextView tv_click;
        TextView tv_content;
        TextView tv_author;
    }
}
